using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

namespace Main
{
    // Shared Google Account
    // Username: rolypollservice
    // Password: r0lyp0ll!
    // Question: How awesome are we?
    // Answer: As awesome as a dark lager
    // Email Code Courtesy:
    // http://www.aspcode.net/Send-mail-from-ASPNET-using-your-gmail-account.aspx

    // Email.SendMail("Joe User1, Joe User2", "ju1@test.net, ju2@test.net", "TEST SUBJECT", "TEST BODY");
    public class Email
    {
        public static void SendMail(string sToName,
                                    string sToEmail,
                                    string sSubject,
                                    string sBody)
        {
            // Temporary hard-coded e-mail settings.
            String sHost = "smtp.gmail.com";
            int nPort = 465;
            String sUserName = "rolypollservice";
            String sPassword = "r0lyp0ll!";
            String sFromName = "RolyPoll Service";
            String sFromEmail = "rolypollservice@gmail.com";
            // sToName = "";
            // sToEmail = "";
            // sSubjectr = "The Subject";
            // sBody = "The Body";
            bool fSSL = true;

            if (sToName.Length == 0)
                sToName = sToEmail;
            if (sFromName.Length == 0)
                sFromName = sFromEmail;
            System.Web.Mail.MailMessage Mail = new System.Web.Mail.MailMessage();
            Mail.Fields["http://schemas.microsoft.com/cdo/configuration/smtpserver"] = sHost;
            Mail.Fields["http://schemas.microsoft.com/cdo/configuration/sendusing"] = 2;
            Mail.Fields["http://schemas.microsoft.com/cdo/configuration/smtpserverport"] = nPort.ToString();
            if (fSSL)
                Mail.Fields["http://schemas.microsoft.com/cdo/configuration/smtpusessl"] = "true";
            if (sUserName.Length == 0)
            {
                //Ingen auth
            }
            else
            {
                Mail.Fields["http://schemas.microsoft.com/cdo/configuration/smtpauthenticate"] = 1;
                Mail.Fields["http://schemas.microsoft.com/cdo/configuration/sendusername"] = sUserName;
                Mail.Fields["http://schemas.microsoft.com/cdo/configuration/sendpassword"] = sPassword;
            }
            Mail.To = sToEmail;
            Mail.From = sFromEmail;
            Mail.Subject = sSubject;
            Mail.Body = sBody;
            Mail.BodyFormat = System.Web.Mail.MailFormat.Html;
            System.Web.Mail.SmtpMail.SmtpServer = sHost;
            System.Web.Mail.SmtpMail.Send(Mail);
        }
    }
}